﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace GeoNames2RDF
{
   public class GeoNamesReader : IDisposable
   {
      private StreamReader _streamReader = null;

      private string[] _currentItems = null;

      public GeoNamesReader(StreamReader streamReader)
      {
         this._streamReader = streamReader;
      }

      public bool ReadNextRecord()
      {
         while (true)
         {
            if (this._streamReader.EndOfStream)
               return false;
            string currentString = this._streamReader.ReadLine();
            if (!currentString.StartsWith("#"))
            {
               _currentItems = currentString.Split('\t');
               return true;
            }
            
         }

         return true;
      }

      public string this[int index]
      {
         get
         {
            return _currentItems[index];
         }
      }

      #region IDisposable Members

      public void Dispose()
      {
         if (this._streamReader != null)
            this._streamReader.Close();
      }

      #endregion
   }
}
